package com.example.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.AjaxResult;
import com.example.system.domain.SysUser;
import com.example.system.mapper.UserMapper;
import com.example.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl extends ServiceImpl<UserMapper, SysUser> implements SysUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public AjaxResult login(SysUser user) {
        LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysUser::getUserName,user.getUserName())
                .eq(SysUser::getPassword,user.getPassword());
        SysUser u = userMapper.selectOne(wrapper);
        if(u == null){
            return AjaxResult.error(500,"用户或者密码输入错误");
        }
        String token = "sYFLHgYFjOYfRYfOYGghftYFUOfyfftITFOFhfTYTFOhoyfFYOYFlkkFDLHFHOIYFKotfhFFFKHtKFTFkjgIfgGFIkIFG";
        AjaxResult ajax = AjaxResult.success();
        return AjaxResult.success().put("token",token);
    }

    @Override
    public List<SysUser> selectUserList(SysUser user) {
        LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
        return userMapper.selectList(wrapper);
    }

    @Override
    public SysUser selectUserByUserName(String userName) {
        LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysUser::getUserName,userName);
        SysUser u = userMapper.selectOne(wrapper);
        return u;
    }
}
